﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/3/2009
 * Time: 3:17 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of ShiftForm.
	/// </summary>
	public partial class ShiftForm : BaseForm
	{
		public ShiftForm() : this(new Shift())
		{
			
		}
		
		public ShiftForm(Shift s)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Model = s;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Shift s = Model as Shift;
			textBoxNotes.Text = s.Notes;
			textBoxRegularHours.Text = s.RegularHours.ToString("0.00");
			textBoxGracePeriod.Text = s.GracePeriod.ToString("0.00");
			checkBoxInactive.Checked = s.Inactive;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Shift s = Model as Shift;
			s.Notes = textBoxNotes.Text;
			s.RegularHours = Util.ConvertUtility.ToDouble(textBoxRegularHours.Text);
			s.GracePeriod = Util.ConvertUtility.ToDouble(textBoxGracePeriod.Text);
			s.Inactive = checkBoxInactive.Checked;
			SessionFacade.SaveOrUpdateShift(s);
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
